<?php
/**
 * 打包控制器
 * @author Giles
 * @package webscoket
 *
 */

namespace Statistics\Modules;

function package()
{
    //$cerkey = array(
    //    1 => 'iPhone Developer: Zhibin Wang (7R28ZQL59M)',
    //    2 => 'iPhone Distribution: Firefly Lighting Co., Ltd.',
    //    3 => 'iPhone Distribution: JiangXi Yingtan Jiahao Machinery Co., Ltd.',
    //    4 => 'iPhone Distribution: Shenzhen Chuangqing Technology Co., Ltd.',
    //    5 => 'iPhone Distribution: Silver Age Engineering Plastics (Dongguan) Co., Ltd.',
    //);
    //check_auth();
    //$userName = system('whoami');
    $userName = getUser();

    $tagList = array(
        1 => '1.0.2',
        2 => '1.0.3',
        3 => '1.0.5',
        4 => '1.0.7',
        5 => '2.0.1'
    );

    $vesion = isset($_GET['version']) ? $_GET['version'] : '';
    //$cerkeyget = isset($_GET['cerkey']) ? $_GET['cerkey'] : '';
    $tag    = isset($_GET['tag']) ? $_GET['tag'] : '';
    $type = isset($_GET['type']) ? $_GET['type'] : '';
    //file_put_contents('log.log', $vesion."\n", FILE_APPEND);

    //$cerkOptions = '';
    //foreach($cerkey as $key => $val)
    //{
    //    $cerkOptions .= "\n<option value='$key'> $val </option>";
    //}

    $tagOption = '';
    foreach($tagList as $key=>$val)
    {
        $tagOption .= "\n<option value='$key'> $val </option>";
    }

    if($userName == 'Giles') 
    {
        $downIp = 'http://127.0.0.1';
        $downUrl = 'http://upload.giles.cc';
    } else {
        $downIp = 'http://192.168.1.157:8080';
        $downUrl = 'http://192.168.1.157:8080';
    }

    if(!empty($vesion)) {
        $cmd = "sh". ROOT_PATH."web/build.sh $vesion $type ".$tagList[$tag];
        $res = system($cmd);
    }
    $url = 'http://192.168.1.157:8080/package/iiapple.'.date('YmdH').'.ipa.zip';

    include ST_ROOT . '/Views/header.tpl.php';
    include ST_ROOT . '/Views/package.tpl.php';
    include ST_ROOT . '/Views/footer.tpl.php';
}